
package com.joinlabs.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.joinlabs.entity.Forwarding;
import com.joinlabs.entity.Group;
import com.joinlabs.entity.Log;
import com.joinlabs.entity.Topic;
import com.joinlabs.entity.User;
import com.joinlabs.entity.Weibo;
import com.joinlabs.service.IForwardService;
import com.joinlabs.service.IGroupService;
import com.joinlabs.service.ILogService;
import com.joinlabs.service.ITopicService;
import com.joinlabs.service.IUserService;
import com.joinlabs.service.IWeiboService;

@Controller
@RequestMapping("/Homepage")
@SessionAttributes(names= {"user","fleg1","gAndf1"})
public class GeRenHomePageAction {

	@Resource
	private IUserService userService;//用户
	@Resource
	private ITopicService topicService;//话题
	@Resource
	private IWeiboService weiboService;//微博
	@Resource
	private IForwardService forwardService;//转发
	@Resource
	private ILogService logService;//日志
	@Resource
	private IGroupService groupService;
/***************************页面跳转*************************************************************************/		
	@RequestMapping("/showHomePage")
	public String showTaDeHomePage(ModelMap map,long userId) {
		//模拟一个登录成功的用户
		User user = userService.selectByPrimaryKey((long)userId);
			
		//添加到session域中
		map.addAttribute("user", user);
		
		//查出全部微博
//		List<Weibo> GeRenweiboList = weiboService.selectWeiboById(user.getUserId());
//		map.addAttribute("GeRenweiboList", GeRenweiboList);
		
		/*//查询所有转发微博
		List<Forwarding> forwardList = forwardService.selectAllForward();
		map.addAttribute("forwardList", forwardList);
		System.out.println(forwardList);
		//查询所有日志
		List<Log> logList = logService.selectAllLog();
		map.addAttribute("logList", logList);
		//显示热门话题
		List<Topic> topicList = topicService.selectRecentTopic();
		map.addAttribute("topicList", topicList);
		*/
		return "/GeRenHomePage/HomePage_ShuoShuo";
	}
	
	@RequestMapping("/showHomePage2")
	public String showTaDeHomePage2(ModelMap map, String fleg1,int userid) {
		//模拟一个登录成功的用户
		User user = userService.selectByPrimaryKey((long)userid);
			
		//添加到session域中
		map.addAttribute("user", user);
				
//		//查出全部微博
//		List<Weibo> GeRenweiboList = weiboService.selectWeiboById(user.getUserId());
//		
//		map.addAttribute("GeRenweiboList", GeRenweiboList);
		
		map.addAttribute("fleg1", fleg1);
	//	System.out.println(map.get(fleg1));
		
		
		return "/GeRenHomePage/HomePage_ShuoShuo";
	}
	@RequestMapping("/showHomePage3")
	public String showTaDeHomePage3(ModelMap map, String fleg1,int userid,int EIflog,User user) {
		//模拟一个登录成功的用户
		User user1 = userService.selectByPrimaryKey((long)userid);
			
		//添加到session域中
		map.addAttribute("user", user1);
		
		
		System.out.println(user);
//		//查出全部微博
//		List<Weibo> GeRenweiboList = weiboService.selectWeiboById(user.getUserId());
//		
//		map.addAttribute("GeRenweiboList", GeRenweiboList);
		map.addAttribute("EIflog", EIflog);
		map.addAttribute("fleg1", fleg1);
		
		
		
		return "/GeRenHomePage/HomePage_ShuoShuo";
	}
	@RequestMapping("/showHomePage4")
	public String showTaDeHomePage4(ModelMap map,User user,int EIflog) {
		//模拟一个登录成功的用户
		
		String sheng = user.getSheng();
		String shi = user.getShi();
		if(sheng.equals("请选择")) {
			user.setUserAddress(null);
		}else if(shi.equals("请选择") || shi.equals("0") ){
			user.setUserAddress(sheng);
		}else {
			user.setUserAddress(sheng+"-"+shi);
		}
		
		
		if(user.getUserSexual().length()>1) {
				user.setUserSexual("双向恋");
		}
		if(user.getUserMood().equals("请选择") || user.getUserMood().equals("")) {
			user.setUserMood(null);
		}
		if(user.getUserBlood().equals("请选择") || user.getUserBlood().equals("")) {
			user.setUserBlood(null);
		}
		if(user.getUserName().equals("请选择") || user.getUserName().equals("")) {
			user.setUserName(null);
		}
		if(user.getUserBoke().equals("请选择") || user.getUserBoke().equals("")) {
			user.setUserBoke(null);
		}
		
		
		
		if(user.getUserBirthday().equals("请选择") || user.getUserBirthday().equals("")) {
			user.setUserBirthday(null);
		}
		if(user.getUserHabituri().equals("请选择") || user.getUserHabituri().equals("")) {
			user.setUserHabituri(null);
		}
		if(user.getUserIntroduce().equals("请选择") || user.getUserIntroduce().equals("")) {
			user.setUserIntroduce(null);
		}
		if(user.getUserPost().equals("请选择") || user.getUserPost().equals("")) {
			user.setUserPost(null);
		}
		if(user.getUserQq().equals("请选择") || user.getUserQq().equals("")) {
			user.setUserQq(null);
		}
		if(user.getUserMsn().equals("请选择") || user.getUserMsn().equals("")) {
			user.setUserMsn(null);
		}
		if(user.getUserProfession().equals("请选择") || user.getUserProfession().equals("")) {
			user.setUserProfession(null);
		}
		if(user.getUserEduc().equals("请选择") || user.getUserEduc().equals("")) {
			user.setUserEduc(null);
		}
		
		userService.updateUserService(user);
		
		String fleg1 = "0";
		map.addAttribute("EIflog", EIflog);
		map.addAttribute("fleg1", fleg1);
		
		User user1 = userService.selectByPrimaryKey((long)user.getUserId());
		
		//添加到session域中
		map.addAttribute("user", user1);
		
		
		return "/GeRenHomePage/HomePage_ShuoShuo";
	}
	
	
	
	@RequestMapping("/showHomePageShuoShuo")
	public String showHomePageShuoShuo(ModelMap map,int userid) {
		
		
		User user = userService.selectByPrimaryKey((long)userid);
		//查出全部微博
		List<Weibo> GeRenweiboList = weiboService.selectWeiboById((long)userid);
		
		
		map.addAttribute("GeRenweiboList", GeRenweiboList);
		
		map.addAttribute("user", user);
		return "/GeRenHomePage/HomePage_ShuoShuo_lo";
	}
	@RequestMapping("/showHomePageShuoShuo2")
	public String showHomePageShuoShuo2(ModelMap map,int userid,int EIflog) {
		
		
		User user = userService.selectByPrimaryKey((long)userid);
		//查出全部微博
		List<Weibo> GeRenweiboList = weiboService.selectWeiboById((long)userid);
		
		System.out.println(GeRenweiboList);
		map.addAttribute("GeRenweiboList", GeRenweiboList);
		map.addAttribute("EIflog", EIflog);
		
		map.addAttribute("user", user);
		return "/GeRenHomePage/HomePage_ShuoShuo_lo";
	}
	
	@RequestMapping("/showHomePageShuoShuo3")
	public String showHomePageShuoShuo3(ModelMap map,int userid,int EIflog,User user) {
		
		System.out.println("我是showHomePageShuoShuo方法的user："+userid);
		User user1 = userService.selectByPrimaryKey((long)userid);
		System.out.println("我是showHomePageShuoShuo3里的user"+user);
		
		
		
		//查出全部微博
		List<Weibo> GeRenweiboList = weiboService.selectWeiboById((long)userid);
		
		System.out.println(GeRenweiboList);
		map.addAttribute("GeRenweiboList", GeRenweiboList);
		map.addAttribute("EIflog", EIflog);
		System.out.println("我是说说lo的标志啊"+EIflog);
		map.addAttribute("user", user1);
		return "/GeRenHomePage/HomePage_ShuoShuo_lo";
	}
	
	@RequestMapping("/chuangjianfengzhu123")
	@ResponseBody
	public String chuangjianfengzhu123(ModelMap map,int userid,String ZuMin) {
		
		
		groupService.insertNewFenZuService(userid, ZuMin);
		
		System.out.println(ZuMin);
		return "success";
	}
	
	@RequestMapping("/showHomePageGuanZu")
	public String showHomePageGuanZu(ModelMap map,int userid) {
		String fleg1;
		fleg1=(String) map.get("fleg1");
		String gAndf = fleg1;
		fleg1 = "0";
		List<Group> group = groupService.selecGroupChengYuan(userid);
		
		map.addAttribute("group", group);
		map.addAttribute("fleg1", fleg1);
		map.addAttribute("gAndf", gAndf);
		return "/GeRenHomePage/HomePage_GuanZhu";
	}
	
////////////////////////////////////////////////////////////////////////////////////////////	
	@RequestMapping("/showHomePageEF")
	public String showHomePageEF(ModelMap map,int userid) {
				User user = userService.selectByPrimaryKey((long)userid);
				
				//添加到session域中
				map.addAttribute("user", user);
				
//		return "/GeRenHomePage/EditInfo";
		return "/GeRenHomePage/EI";		
	}
	@RequestMapping("/showHomePageEF2")
	public String showHomePageEF2(ModelMap map,int userid) {
				
				
//				int rs = userService.updateUserService(user);	
				User user = userService.selectByPrimaryKey((long)userid);
				
				//添加到session域中
				map.addAttribute("user", user);
				
//		return "/GeRenHomePage/EditInfo";
		return "/GeRenHomePage/EI2";		
	}


	
	@RequestMapping("/showShuoshuokuang")
	public String showShuoshuokuang(ModelMap map,int userid) {
				//模拟一个登录成功的用户
				User user = userService.selectByPrimaryKey((long)userid);
					
				//添加到session域中
				map.addAttribute("user", user);
				
				//查出全部微博
				List<Weibo> GeRenweiboList = weiboService.selectWeiboById(user.getUserId());
				map.addAttribute("GeRenweiboList", GeRenweiboList);
				for (Weibo weibo : GeRenweiboList) {
					System.out.println(weibo.getUser().getUserName());
					System.out.println(weibo.getWeiboContent());
					System.out.println(weibo.getUser().getUserHeadpath());
					System.out.println("********************************");
					System.out.println("********************************");
					System.out.println("********************************");
				}
		return "/GeRenHomePage/HomePage_main_shuoshuokuang";
	}
	@RequestMapping("/showFansKuang")
	public String showFansKuang(ModelMap map,int userid) {
		List<User> Fans = userService.selectFansById((long)userid);
		map.addAttribute("Fans", Fans);
		System.out.println(Fans);
		return "/GeRenHomePage/HomePage_fenshiKuang";
	}
	@RequestMapping("/showGuanZuKuang")
	public String showGuanZuKuang(ModelMap map,int userid) {
		//查询登录用户的所有分组
		List<Group> FenZu=groupService.selecGroupChengYuan(userid);
		//查询登录用户所有关注的用户
		List<User> GZ = userService.selectGZById((long)userid);
		map.addAttribute("FenZu", FenZu);
		
		map.addAttribute("GZ", GZ);
		return "/GeRenHomePage/HomePage_GuZuKuang";
	}
	@RequestMapping("/showGuanZuKuang2")
	public String showGuanZuKuang2(ModelMap map,int userid,int zuid) {
		//模拟一个登录成功的用户
		User user = userService.selectByPrimaryKey((long)userid);
			
		//添加到session域中
		map.addAttribute("user", user);

		List<Group> FenZu=groupService.selecGroupChengYuan(userid);
		//查询分组成员
		List<User> GZ = userService.selectFenZuChengYuanById((long)userid,zuid);
		
		map.addAttribute("FenZu", FenZu);
		map.addAttribute("GZ", GZ);
		return "/GeRenHomePage/HomePage_GuZuKuang";
	}
	
	@RequestMapping("/showGuanZuKuang3")
	public String showGuanZuKuang3(ModelMap map,int userid) {
		//模拟一个登录成功的用户
		User user = userService.selectByPrimaryKey((long)userid);
			
		//添加到session域中
		map.addAttribute("user", user);
		
		List<Group> FenZu=groupService.selecGroupChengYuan(userid);
		//查询分组成员
		List<User> GZ = userService.selectWeiFenZuChengYuanById((long)userid);
		System.out.println("showGuanZuKuang3d的关注"+GZ);
		map.addAttribute("FenZu", FenZu);
		map.addAttribute("GZ", GZ);
		return "/GeRenHomePage/HomePage_GuZuKuang";
	}
	
	@RequestMapping("/insertFenZu")
	@ResponseBody
	public String insertFenZu(ModelMap map,int userid,int zuid,String xuyaoxiugai) {
		//模拟一个登录成功的用户
		if(xuyaoxiugai.equals(1)) {
			System.out.println(xuyaoxiugai);
			long deleteZuid =  groupService.selecZuIdByZuNameService(userid,xuyaoxiugai);
			long rs =  groupService.deleteFenZuByZuiId(deleteZuid);
			if(rs>0) {
				 rs = groupService.insertFenZuService(userid,zuid);
				 if(rs > 0) {
					 return "success";
				 }
			}
		}else {
			 int rs = groupService.insertFenZuService(userid,zuid);
			 if(rs > 0) {
				 return "success";
			 }
		}
		
		
		
		
		
		return "er";
	}
	
	
/****************************************************************************************************/
}
